from PySide6.QtWidgets import QApplication,QMainWindow,QPushButton,QVBoxLayout,QWidget,QFileDialog
from PySide6.QtGui import QPixmap,QDesktopServices
from PySide6.QtCore import Qt,QUrl
from hats_detection.video_worker import worker_process_video
from hats_detection.image_worker import worker_process_image


class MainWindow(QMainWindow):
    def __init__(self):
        super().__init__()
        self.setWindowTitle("帽子检测系统")

        #创建按钮
        self.process_video_button = QPushButton("处理视频",self)
        self.process_video_button.clicked.connect(self.process_video)


        self.process_image_button = QPushButton("处理图片",self)
        self.process_image_button.clicked.connect(self.process_image)

        #创建布局
        layout = QVBoxLayout()

        #把按钮添加到布局中
        layout.addWidget(self.process_video_button)
        layout.addWidget(self.process_image_button)

        container = QWidget()
        container.setLayout(layout)
        self.setCentralWidget(container)

    def process_video(self):
        video_path,_ = QFileDialog.getOpenFileName(self,"选择视频文件","","*.mp4")
        if video_path:
            worker_process_video(video_path)
    
    def process_image(self):
        image_path,_ = QFileDialog.getOpenFileName(self,"选择图片文件","","*.jpg")
        if image_path:
            worker_process_image(image_path)
